#!/usr/bin/python3 
# -*- coding: utf-8 -*- 
# @author : shenLangBo 
# @desc: 
# 时  间：2023-12-03 20:29

# 方法1. 在 python 中，将 GB 系列的字节串转换为 python 字节串
with open('file/gb2312.txt', 'rb') as fr:
    content = fr.read()
    print(content)
    # 将 GB 系列的字节串转换为 python 字节串
    # s = content.decode('gb2312')
    # s = content.decode('gbk')
    s = content.decode('gb18030')
    print(s)

with open('file/utf-8.txt', 'rb') as fr:
    content = fr.read()
    print(content)
    # 将 GB 系列的字节串转换为 python 字节串
    # s = content.decode('gb2312')
    # s = content.decode('gbk')
    s = content.decode('utf-8')
    print(s)

# 方法2. 在 open 函数中，指定字节串解码为字符的方式。直接以文本的格式操作文件
with open('./file/gb2312.txt', 'r', encoding='gb2312') as fr:
    content = fr.read()
    print(content)

with open('./file/utf-8.txt', 'r', encoding='utf-8') as fr:
    content = fr.read()
    print(content)


